package com.chinafree.auth.service.impl;

import com.chinafree.auth.model.bo.TokenMap;
import com.chinafree.auth.service.TokenService;
import com.chinafree.common.utils.JWTUtils;
import com.chinafree.model.enumeration.JWTValue;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class TokenServiceImpl implements TokenService {

    @Override
    public String getToken(TokenMap tokenMap) {
        Map<String, Object> map = new HashMap<>();
        if (tokenMap.getUserId() != null) {
            map.put(JWTValue.USER_ID.getValue(), tokenMap.getUserId());
        }
        if (tokenMap.getRoleId() != null) {
            map.put(JWTValue.ROLE_ID.getValue(), tokenMap.getRoleId());
        }
        if (null != tokenMap.getCompanyId()) {
            map.put(JWTValue.COMPANY_ID.getValue(), tokenMap.getCompanyId());
        }
        return JWTUtils.getToken(map);
    }
}
